package com.iqiyi.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.iqiyi.domain.Actor;
import com.iqiyi.domain.ActorRegion;
import com.iqiyi.domain.Region;
import com.iqiyi.entity.ActorVo;
import com.iqiyi.mapper.ActorRegionMapper;
import com.iqiyi.service.ActorService;
import com.iqiyi.mapper.ActorMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
* @author 11757
* @description 针对表【actor】的数据库操作Service实现
* @createDate 2022-12-17 12:14:03
*/
@Service
public class ActorServiceImpl extends ServiceImpl<ActorMapper, Actor>
    implements ActorService{

    @Resource
    private ActorMapper actorMapper;
@Resource
private ActorRegionMapper actorRegionMapper;

    @Override
    public List<ActorVo> findAll() {
        return actorMapper.findAll();
    }
    //往演员表中插入值
    public boolean saveActor(Actor actor){
        if(actorMapper.addActor(actor)!=0){
            return true;
        }else{
            return false;
        }
    }
     public List<ActorVo> getActorByid(int id){
        List<ActorVo> actorVo=actorMapper.getActorByid(id);
        return actorVo;
     }
    public boolean delActor(int id){
        if(actorMapper.delActor1(id)!=0&&actorRegionMapper.delActor2(id)!=0){
            return true;
        }else{
            return false;
        }
    }
    public void updateActor(ActorVo Actor){
        //更新演员表
        actorMapper.updateActor(Actor);
        //先删中间表记录
        actorRegionMapper.delActor2(Actor.getId());
        //往里加
        List<Region>regions=Actor.getRegions();
        for (Region r:regions
             ) {
            ActorRegion actorRegion=new ActorRegion();
            actorRegion.setActorid(Actor.getId());
            actorRegion.setRegionid(r.getId());
            System.out.println(actorRegion);
            actorRegionMapper.saveRegion(actorRegion);
        }
    }
}




